<template>
  <!-- 总承包管理费 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData
      :searchData="searchArr"
      @search="search"
    ></searchData>
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title"></title-name> -->
      <a-button
        class="mb12"
        icon="plus"
        type="primary"
        @click="handleManage(2)"
        v-btnPermission="'bm_026_add_01'"
      >新增</a-button>
      <a-alert
        class="mb12"
        type="info"
        show-icon
      >
        <template slot="message">
          <span>
            本月业主确权(含过账甲指)(含税)(万元)：
            <a>{{ statistics.totalMonthDefine }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            本月实际产值(含过账甲指)(含税)(万元):
            <a>{{ statistics.totalMonthFact }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            年度业主确权(含过账甲指)(含税)(万元)：
            <a>{{ statistics.totalYearDefine }}</a> </span><br />
          <span>
            年度实际产值(含过账甲指)(含税)(万元)：
            <a>{{ statistics.totalYearFact }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            累计业主确权(含过账甲指)(含税)(万元):
            <a>{{ statistics.totalAccumulativeDefine }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            累计实际产值(含过账甲指)(含税)(万元)：
            <a>{{ statistics.totalAccumulativeFact }}</a>
          </span>
        </template>
      </a-alert>
      <!-- 表格 -->
      <list-table
        ref="table"
        tableLayout="fixed"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <template
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
          <a
            @click="handleManage(0, record)"
            v-btnPermission="'bm_026_loo_04'"
          >查看</a>
          <!-- 编辑 -->
          <span
            v-if="record.status != 'SUBMITTED' && record.status != 'PAST' && record.status != 'ABOLISH'"
            v-btnPermission="'bm_026_edi_02'"
          >
            <a @click="handleManage(1, record)">编辑</a>
          </span>
          <!-- 撤销 -->
          <span v-if="record.status == 'SUBMITTED' && selfBtnShow(record.creatorId)&&hideBuquBtn()">
            <a @click="handleUndo({ id: record.id, type: 3 })">撤销</a>
          </span>
          <!-- 作废 -->
          <span
            v-if="record.status == 'PAST'"
            v-btnPermission="'bm_026_tov_05'"
          >
            <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
          </span>
          <!-- 删除 -->
          <span
            v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"
            v-btnPermission="'bm_026_del_03'"
          >
            <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
          </span>
          <span
            v-if="
                            record.status === 'PAST' ||
                            record.status === 'SUBMITTED' ||
                            record.status === 'REJECTED' ||
                            record.status === 'ABOLISH'
                        "
            v-btnPermission="'bm_026_loo_04'"
          >
            <approval-button
              :status="record.status"
              :id="record.id"
            ></approval-button>
          </span>
          </MoreButton>
        </template>
        <template
          slot="status"
          slot-scope="text, record"
        >
          <list-status
            :status="record.status"
            conversion="en"
            :is-approval="true"
            :text="text"
          />
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getMeasureList, delMeasure, getMeasureCount } from '@/api/businessAffairs/lumpSumMeasurement'
// import { getPageUnionActivity, deleteUnionActivity, addUnionBookHouseImport } from '@/api/union/culturalActivities' // api
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import moment from 'moment'
const searchArr = [
  // 搜索框
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchComId',
  //   type: SelectSubCompany
  // },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchComId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  {
    name: '填报人',
    type: 'input',
    value: 'creatorName'
  },
  {
    name: '填报时间',
    type: 'dateRange',
    value: 'activityDate',
    attr: {
      rangeFormat: ['createTimeBegin', 'createTimeEnd']
    }
  },
  {
    name: '月份',
    type: 'month',
    value: 'measureMonth',
    attrs: {
      valueFormat: 'YYYY-MM'
    }
  },
  {
    name: '状态',
    type: 'select',
    value: 'status',
    data: [
      {
        label: '待提交审批',
        value: 'DRAFT'
      },
      {
        label: '审批中',
        value: 'SUBMITTED'
      },
      {
        label: '审批通过',
        value: 'PAST'
      },
      {
        label: '审批不通过',
        value: 'REJECTED'
      },
      {
        label: '已作废',
        value: 'ABOLISH'
      }
    ]
  }
]
const columns = [
  // {
  //     title: '序号',
  //     width: 80,
  //     dataIndex: 'index',
  //     customRender() {
  //         return arguments[2] + 1
  //     }
  // },
  {
    title: '所属分公司',
    dataIndex: 'branchCompanyName'
  },

  {
    title: '所属项目',
    dataIndex: 'projectName'
  },
  {
    title: '计量月份',
    dataIndex: 'measureMonth',
    width: 100
  },
  {
    title: '本月确权(含税)(万元)',
    dataIndex: 'monthDefine'
  },
  {
    title: '年度累计确权(含税)(万元)',
    dataIndex: 'yearAccumulativeDefine'
  },
  {
    title: '累计确权(含税)(万元)',
    dataIndex: 'accumulativeDefine'
  },
  {
    title: '本月实际产值(含税)(万元)',
    dataIndex: 'monthFactOutput'
  },
  {
    title: '年度实际产值(含税)(万元)',
    dataIndex: 'yearFactOutput'
  },
  {
    title: '累计实际产值(含税)(万元)',
    dataIndex: 'accumulativeFactOutput'
  },
  {
    title: '本月付款金额(含税)(万元)',
    dataIndex: 'monthPayDefine'
  },
  {
    title: '填报人',
    dataIndex: 'creatorName'
  },
  {
    title: '填报时间',
    dataIndex: 'createTime',
    customRender() {
      return moment(arguments[0]).format('YYYY-MM-DD')
    }
  },
  {
    title: '状态',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    fixed: 'right',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      statistics: {
        totalAccumulativeDefine: 0,
        totalAccumulativeFact: 0,
        totalMonthDefine: 0,
        totalMonthFact: 0,
        totalYearDefine: 0,
        totalYearFact: 0
      }, //统计
      userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
      loadData: async (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        this.getMeasureCount(requestParameters)
        const [err, res] = await getMeasureList(requestParameters)
        return new Promise((resolve, reject) => {
          if (err) {
            reject(err)
          } else {
            resolve(res)
          }
        })
      },

      removeApi: { remove: delMeasure, invalid: delMeasure, undo: delMeasure } // api
    }
  },
  methods: {
    async getMeasureCount(requestParameters) {
      const [err, res] = await getMeasureCount(requestParameters)
      if (!err) {
        this.statistics = res.data
      }
    },
    // 搜索
    search(value) {
      if (value.overrideTotalManagementFee) {
        value.overrideTotalManagementFee = value.overrideTotalManagementFee == '1'
      }

      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'updateRealProduct',
        query
      })
    }
  }
}
</script>
